package com.yishan.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.yishan.dao.DeptDao;
import com.yishan.domain.Dept;
import com.yishan.service.DeptService;
import java.util.List;
import java.util.UUID;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * @Author yishan
 * @Date 2021/4/28 0028 1:22
 * @Version 1.0
 */
@Service
public class DeptServiceImpl implements DeptService {

	@Autowired
	private DeptDao deptDao;

	@Override
	public void save(Dept dept) {

		// id使用UUID的生成策略来获取
		String id = UUID.randomUUID().toString().replace("-","").substring(0,15);
		dept.setId(id);
		deptDao.save(dept);

	}

	@Override
	public void delete(String id) {
		deptDao.delete(id);
	}


	@Override
	public void deleteMany(String ids) {
		String[] idss = ids.split(",");
		for (String s : idss) {
			delete(s);
		}
	}

	@Override
	public void update(Dept dept) {

		deptDao.update(dept);

	}

	@Override
	public Dept findById(String id) {

		return deptDao.findById(id);

	}

	@Override
	public List<Dept> findAll() {

		return deptDao.findAll();

	}

	@Override
	public PageInfo findAll(int page, int size) {

		PageHelper.startPage(page,size);
		List<Dept> list = deptDao.findAll();
		return new PageInfo(list);

	}
	
	
}
